package com.zhang.spark_1.test

import java.io.{ObjectOutputStream, OutputStream}
import java.net.Socket

/**
 * @title:
 * @author: zhang
 * @date: 2021/12/5 10:46 
 */
object Driver {
  def main(args: Array[String]): Unit = {

    val client1 = new Socket("localhost", 9999)
    val client2 = new Socket("localhost", 8888)
    val task = new Task()
    //client1
    val out1: OutputStream = client1.getOutputStream()
    val objectOut = new ObjectOutputStream(out1)
    val subTask1 = new SubTask()
    subTask1.datas = task.datas.take(2)
    subTask1.op = task.op
    objectOut.writeObject(subTask1)
    objectOut.flush()
    objectOut.close()
    println("客户端1发送完毕")
    client1.close()

    //client2
    val out2: OutputStream = client2.getOutputStream()
    val objectOut2 = new ObjectOutputStream(out2)
    val subTask2 = new SubTask()
    subTask2.datas = task.datas.takeRight(2)
    subTask2.op = task.op
    objectOut2.writeObject(subTask2)
    objectOut2.flush()
    objectOut2.close()
    println("客户端2发送完毕")
    client2.close()
  }

}
